package com.likou.written.zhijia;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Author: 陈桂明
 * Date: 2025/10/12 22:27
 * Description: zhijia2
 */
public class zhijia2 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        // 注意 hasNext 和 hasNextLine 的区别
        // while (in.hasNextInt()) { // 注意 while 处理多个 case
        //     int a = in.nextInt();
        //     int b = in.nextInt();
        //     System.out.println(a + b);
        // }
        int n = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }

        int ans = 0;
        int[] preSum = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            preSum[i] = preSum[i - 1] + nums[i - 1];
        }
        int[] sortPreSum = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            int left = 0;
            int right = i;
            int pos = -1;
            while (left <= right) {
                int mid = left + (right - left) / 2;
                if (sortPreSum[mid] < preSum[i]) {
                    pos = mid;
                    left = mid + 1;
                } else {
                    right = mid - 1;
                }
            }
            ans += (pos + 1);
            int insertPos = 0;
            while (insertPos < i && sortPreSum[insertPos] < preSum[i]) {
                insertPos++;
            }
            for (int j = i; j > insertPos; j--) {
                sortPreSum[j] = sortPreSum[j - 1];
            }
            sortPreSum[insertPos] = preSum[i];
        }

        System.out.println(ans);
    }

}
